package UIComponents
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Apr 24, 2012 3:58:27 PM 
	 */ 
	public class CommHzDayGift extends Sprite
	{
		private var xjnhzBtn:DisplayObject;
		private var kthz:DisplayObject;
		
		private var hzIcon:IconContainer;
		
		private var item3:IconContainer; 
		
		private var itemNum3:TextField;
		
		private var nextItem1:IconContainer;
		private var nextItem2:IconContainer;
		
		private var nextNum1:TextField;
		private var nextNum2:TextField;
		
		private var newTip:TextField;
		
		public function CommHzDayGift()
		{
			init();
		}
		
		private function init():void
		{
			xjnhzBtn=this.getChildByName("xhhz");
			kthz=this.getChildByName("ktnhz");
			
			hzIcon=this.getChildByName("hzIcon") as IconContainer;
			
			item3=this.getChildByName("item3") as IconContainer;
			
			itemNum3=this.getChildByName("itemNum3") as TextField;
			
			nextItem1=this.getChildByName("nextItem1") as IconContainer;
			nextItem2=this.getChildByName("nextItem2") as IconContainer;
			nextNum1=this.getChildByName("nextNum1") as TextField;
			nextNum2=this.getChildByName("nextNum2") as TextField;
			
			newTip=this.getChildByName("tips") as TextField;
			
			this.xjnhzBtn.addEventListener(MouseEvent.CLICK,yhzFun);
			kthz.addEventListener(MouseEvent.CLICK,hzFun);
			
			this.newTip.selectable=false;
			(this.getChildByName("itemNum1") as TextField).selectable=false;
			(this.getChildByName("itemNum2") as TextField).selectable=false;
			this.itemNum3.selectable=false;
			this.nextNum1.selectable=false;
			this.nextNum2.selectable=false;
		}
		
		private function yhzFun(e:Event):void
		{
			navigateToURL(new URLRequest(FlatInfo.qqYearVipLink));
		}
		private function hzFun(e:Event):void
		{
			navigateToURL(new URLRequest(FlatInfo.vipLink));
		}
		
		private function reset():void
		{
			this.getChildByName("itembg1").visible=false;
			this.getChildByName("itembg2").visible=false;
		}
		
		public function setDataInfo(lv:int,dayArr:Array,yearObj:Object,nextArr:Array):void
		{
			this.reset();
			this.hzIcon.addPic(new (ApplicationDomain.currentDomain.getDefinition("v"+lv) as Class));
//			trace("1111");
			for(var i:int=0;i<dayArr.length;i++)
			{
				var obj:Object=dayArr[i];
				var dis:DisplayObject=null;
				var des:String="";
				if(obj)
				{
					dis=obj.icon;
					dis.width=65;
					dis.height=65;
					des=dis["displayViewIconName"];
				}
//				trace("2222"+i);
				(this.getChildByName("item"+(i+1)) as IconContainer).addPic(dis,des);
				(this.getChildByName("itemNum"+(i+1)) as TextField).text="X"+obj.itemNum;
				this.getChildByName("itembg"+(i+1)).visible=true;
			}
			
			this.item3.addPic(yearObj.icon,yearObj.icon["displayViewIconName"]);
			this.itemNum3.text="X"+yearObj.itemNum;
//			trace("4444");
			if(null!=nextArr)
			{
//				trace("555");
				for(var j:int=0;j<nextArr.length;j++)
				{
					var tmpObj:Object=nextArr[j];
					var dis2:DisplayObject=null;
					var des2:String="";
					if(tmpObj)
					{
						dis2=tmpObj.icon;
						dis2.width=28;
						dis2.height=28;
						des2=dis2["displayViewIconName"];
					}
					(this.getChildByName("nextItem"+(j+1)) as IconContainer).addPic(dis2,des2);
					(this.getChildByName("nextNum"+(j+1)) as TextField).text="X"+tmpObj.itemNum;
//					trace("666"+j);
				}
			}
			
			if(lv>=8)
			{
				this.nextItem1.visible=this.nextItem2.visible=this.nextNum1.visible=this.nextNum2.visible=false;
				this.newTip.text="恭喜您成为黄钻最高等级成员，黄钻将竭诚为您提供最贴心的服务。";
				this.newTip.selectable=false;
				this.newTip.autoSize=TextFieldAutoSize.CENTER;
				this.getChildByName("hzbg2").visible=false;
				this.getChildByName("hzbg1").visible=false;
			}else{
				this.nextItem1.visible=this.nextItem2.visible=this.nextNum1.visible=this.nextNum2.visible=true;
				this.newTip.text="当您升级到下一级黄钻贵族，您将获得这些奖励：";
				this.newTip.selectable=false;
				this.newTip.autoSize=TextFieldAutoSize.LEFT;
				this.getChildByName("hzbg2").visible=true;
				this.getChildByName("hzbg1").visible=true;
			}
		}
		
	}
}
